﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

using System.Data;



  public  class datTuan
    {
         SqlCommand cmd;
        SqlDataReader dr;
        public List<entTuan> getAllTuan(int i)
        {
             
            string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr2"].ConnectionString;
            SqlConnection sqlConnection = new SqlConnection(constr);
            sqlConnection.Open();
            cmd = new SqlCommand("sp_TuanGetAll", sqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlParameter[] sqla = new SqlParameter[1];
            sqla[0] = new SqlParameter("hocky", DbType.Int16);
            sqla[0].Value=i;
            cmd.Parameters.AddRange(sqla);
            entTuan entT = new entTuan();
            List<entTuan> lst = new List<entTuan>();
            dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                entT = new entTuan();
                entT.Tuan = int.Parse(dr["tuan"].ToString());
                entT.NgayDau = dr["NgayDau"].ToString();
                entT.NgayCuoi = dr["NgayCuoi"].ToString();
                int k = int.Parse(dr["tuan"].ToString());
                entT.Ten = "Tuần " +k+ " [Từ " + dr["NgayDau"].ToString() + " -- Đến " + dr["NgayCuoi"].ToString()+"]";
                lst.Add(entT);
            }
            dr.Close();
            sqlConnection.Close();
            return lst;
        }
        public int getTuanHienTai()
        {

            string constr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr2"].ConnectionString;
            SqlConnection sqlConnection = new SqlConnection(constr);
            sqlConnection.Open();
            cmd = new SqlCommand("sp_TuanGetTuanHienTai", sqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;

            int i=0;
            string tuan = cmd.ExecuteScalar().ToString();
            if (tuan != "")
            {
                i = int.Parse(tuan);
            }

            sqlConnection.Close();
            return i;
        }
    }

